package Iterator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class StudentSystem {
	private List<Student> list;
	
	public StudentSystem() {
		list = new ArrayList<Student>();
	}
	
	public void add(Student student){
		list.add(student);
	}	
	
	public void remove(Student student){
		list.add(student);
	}
	
	public Iterator getIterator(){
		return new StudentIterator();
	}

	class StudentIterator implements Iterator{
		int cur = 0;
		public StudentIterator() {
			Collections.sort(list
					,(a,b)->{return Integer.compare(a.getAge(),b.getAge());
					});
		}
		
		public boolean hasNext(){
			return cur<list.size();
		}
		
		public Student next(){
			return list.get(cur++);	
		}
		
	}
	
}
